package trial.hel;

import java.util.ArrayList;
import java.util.List;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/29 13:58
 * @描述 62进制加法 0-9 a-b A-B
 *
 *
 * 他人的面试算法题，62进制加法返回结果字符串，手写初步测试正确
 */
public class MeiTuanOther {
    public static void main(String[] args) {
        System.out.println(test("zbc", "zbc"));
        System.out.println(charToInt('o'));
        System.out.println(charToInt('m'));
        System.out.println(charToInt('J'));

//        System.out.println(charToInt('a'));
//        System.out.println(charToInt('z'));
//        System.out.println(charToInt('A'));
//        System.out.println(charToInt('Z'));
//        System.out.println(charToInt('0'));
//        System.out.println(charToInt('9'));
//        System.out.println(intToChar(9));
//        System.out.println(intToChar(36));
//        System.out.println(intToChar(10));
    }
    public static String test(String str1,String str2){
        List<Integer> list1=strToLi(str1);
        List<Integer> list2=strToLi(str2);
        System.out.println(list1);
        System.out.println(list2);
        int index1=0,index2=0,len1=list1.size(),len2=list2.size();
        boolean valid=false;
        StringBuilder sb=new StringBuilder();
        while (index1<len1||index2<len2||valid){
            int bit=0,ans;
            if(valid){
                bit++;
            }
            if(index1<len1){
                bit+=list1.get(index1);
                index1++;
            }
            if(index2<len2){
                bit+=list2.get(index2);
                index2++;
            }
            if(bit/62>0){
                valid=true;
                ans=bit%62;
            }else {
                valid=false;
                ans=bit;
            }
            sb.insert(0,intToChar(ans));
        }
        return sb.toString();
    }
    public static List<Integer> strToLi(String str){
        List<Integer> ans=new ArrayList<>();
        for (int i = str.length()-1; i >=0 ; i--) {
            ans.add(charToInt(str.charAt(i)));
        }
        return ans;
    }
    public static int charToInt(char ch){
        if(ch>='a'&&ch<='z'){
            return ch-'a'+10;
        }else if(ch>='A'&&ch<='Z'){
            return ch-'A'+36;
        }
        return ch-'0';
    }
    public static char intToChar(int value){
        if(value>=10&&value<=35){
            return (char)(value+'a'-10);
        }else if(value>=36&&value<=61){
            return (char)(value+'A'-36);
        }
        return (char)(value+'0');
    }
}
